﻿
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.ComplexEventProcessing;
using Microsoft.ComplexEventProcessing.Adapters;

namespace $Namespace$
{

    /// <summary>
    /// Factory to instantiate a data generator input adapter.
    /// </summary>
    public sealed class $FactoryClassName$ : ITypedInputAdapterFactory<$ConfigClassName$>
                                           //,ITypedDeclareAdvanceTimeProperties<$ConfigClassName$>

        //NOTE: To implement IDeclareAdvanceTimeProperties,uncomment the declaration above
        //      and the implementation of the interface below.
    {

        [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "By Design")]
        public InputAdapterBase Create<TPayload>($ConfigClassName$ configInfo, EventShape eventShape)
        {
            //TODO: Determine if you need anything more sophisticated in the Create.
            //This may include logic to reuse already created adapters.
            InputAdapterBase adapter = default(InputAdapterBase);
            switch (eventShape)
            {
                case EventShape.Edge:
                    adapter = new $EdgeClassName$(configInfo);
                    break; 
                case EventShape.Interval:
                    adapter = new $IntervalClassName$(configInfo);
                    break; 
                case EventShape.Point:
                    adapter = new $PointClassName$(configInfo);
                    break; 
                default:                    
                    throw new ArgumentException(string.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "$FactoryClassName$ cannot instantiate adapter with event shape {0}",
                        eventShape.ToString()));
            }

            return adapter; 
        }

        /// <summary>
        /// Dispose method.
        /// </summary>
        public void Dispose()
        {
        }

        /**
         * Uncomment this section when implementing IDeclareAdvanceTimeSettings.
        /// <summary>
        /// Specifies the CTI behavior of this adapter. This method will be called whenever
        /// a new adapter instance is needed, with the respective configuration and event type.
        /// </summary>
        /// <typeparam name="TPayload">Type of the payload.</typeparam>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <returns>An instance of AdapterAdvanceTimeSettings.</returns>
        [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "By Design")]
        public AdapterAdvanceTimeSettings DeclareAdvanceTimeProperties<TPayload>($ConfigClassName$ configInfo, EventShape eventShape)
        {
            //This will inject a CTI 1 tick after every event and drops any late-arriving packets.
            return new AdapterAdvanceTimeSettings(
                new AdvanceTimeGenerationSettings(1, TimeSpan.FromTicks(-1)),
                AdvanceTimePolicy.Drop);
        }
        **/
    }
}
